﻿using Ruandao;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace TestRuandao
{
    using Ruandao.MiniAccess.SqlServer;
    using Ruandao.MiniAccess;
    using Ruandao.EntityAccess;

    [TestClass()]
    public class TagContextTest
    {


        private TestContext testContextInstance;

        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试属性
        // 
        //编写测试时，还可使用以下属性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///Destroy 的测试
        ///</summary>
        [TestMethod()]
        public void DestroyTest()
        {
            string pathFile = TestContext.TestDeploymentDir + "\\TagTestData.xml";
            new Ruandao.MiniAccess.SqlServer.SqlCommandFile(pathFile).ExecuteCommand();
            TagContext.Destroy("aaa", "aa");
        }

        [TestMethod()]
        public void SaveContentTest()
        {
            int a = DbUtility.GetRecordNumber("RuandaoConnection", "Content");
            int b = DbUtility.GetRecordNumber("RuandaoConnection", "Multitag");
            int c = DbUtility.GetRecordNumber("RuandaoConnection", "MultitagContent");
            Assert.AreEqual(a, 0);
            Assert.AreEqual(b, 0);
            Assert.AreEqual(c, 0);
            PrivateObject param0 = null; // TODO: 初始化为适当的值
            TagContext target = TagContext.GetInstance("bbwen","123"); // TODO: 初始化为适当的值
            Content content = new Content();
            content.Brief = "a";
            content.ContentType = "sd";
            content.CreateDate = System.DateTime.Now;
            content.IsPublic = true;
            content.OriginalId = "1";
            content.PostCount = 2;
            content.ProviderName = "ff";
            content.Rank = 3;
            content.Size = 12;
            content.SizeUnit = "sdf";
            content.StowCount = 3;
            content.Text = "gertgy";
            content.Title = "yrt";
            content.ViewCount = 3;
            content.UserGuid = new System.Guid("11111111-1111-1111-1111-111111111111");// TODO: 初始化为适当的值
            string[] tagNames = {"a","b","c","d","e"}; // TODO: 初始化为适当的值
            target.SaveContent(content, tagNames);
            a = DbUtility.GetRecordNumber("RuandaoConnection", "Content");
            b = DbUtility.GetRecordNumber("RuandaoConnection", "Multitag");
            c = DbUtility.GetRecordNumber("RuandaoConnection", "MultitagContent");
            Assert.AreEqual(a, 1);
            Assert.AreEqual(b, 31);
            Assert.AreEqual(c, 1);
        }

        [TestMethod()]
        public void DeleteTagTest()
        {
            int a1 = DbUtility.GetRecordNumber("RuandaoConnection", "Tag");
            int b1 = DbUtility.GetRecordNumber("RuandaoConnection", "Multitag");
            int c1 = DbUtility.GetRecordNumber("RuandaoConnection", "MultitTagContent");
            PrivateObject param0 = null; // TODO: 初始化为适当的值
            TagContext_Accessor target = new TagContext_Accessor("bbwen", "123"); // TODO: 初始化为适当的值
            string name = "a"; // TODO: 初始化为适当的值
            target.DeleteTag(name);
            int a2 = DbUtility.GetRecordNumber("RuandaoConnection", "Tag");
            int b2 = DbUtility.GetRecordNumber("RuandaoConnection", "Multitag");
            int c2 = DbUtility.GetRecordNumber("RuandaoConnection", "MultitTagContent");
            Assert.AreEqual(a1, a2 + 1);
            Assert.AreEqual(b1, b2 + 15);
            Assert.AreEqual(a1, c2 + 1);
        }

        [TestMethod()]
        public void SaveContentTest1()
        {
            PrivateObject param0 = null; // TODO: 初始化为适当的值
            int a = DbUtility.GetRecordNumber("RuandaoConnection", "Content");
            Assert.AreEqual(a, 0);
            TagContext_Accessor target = new TagContext_Accessor("bbwen", "123"); // TODO: 初始化为适当的值
            Content content = new Content();
            content.Brief = "a";
            content.ContentType = "sd";
            content.CreateDate = System.DateTime.Now;
            content.IsPublic = true;
            content.OriginalId = "1";
            content.PostCount = 2;
            content.ProviderName = "ff";
            content.Rank = 3;
            content.Size = 12;
            content.SizeUnit = "sdf";
            content.StowCount = 3;
            content.Text = "gertgy";
            content.Title = "yrt";
            content.ViewCount = 3;
            content.UserGuid = new System.Guid("11111111-1111-1111-1111-111111111111");// TODO: 初始化为适当的值
            target.SaveContent(content);
            a = DbUtility.GetRecordNumber("RuandaoConnection", "Content");
            Assert.AreEqual(a, 1);
        }

        [TestMethod()]
        public void SearchTest()
        {
            PrivateObject param0 = null; // TODO: 初始化为适当的值
            TagContext_Accessor target = new TagContext_Accessor("bbwen", "123"); // TODO: 初始化为适当的值
            string orderBy = "ViewCount"; // TODO: 初始化为适当的值
            string condition = string.Empty; // TODO: 初始化为适当的值
            int total = 0; // TODO: 初始化为适当的值
            int totalExpected = 2; // TODO: 初始化为适当的值
            int startIndex = 1; // TODO: 初始化为适当的值
            int pageSize = 1; // TODO: 初始化为适当的值
            string[] tags = {"a","b"}; // TODO: 初始化为适当的值
            Content[] actual;
            actual = target.Search(orderBy, condition, out total, startIndex, pageSize, tags);
            Assert.AreEqual(totalExpected, total);
            Assert.AreEqual("", actual[0].OriginalId);
        }
    }
}
